<?php
/**
 * Created by PhpStorm.
 * User: kun
 * Date: 26/6/19
 * Time: 18:20
 */

namespace app\api\controller;

use app\admin\controller\Base;
use app\common\lib\Aes;
use app\common\lib\ali\Sms;
use app\common\lib\Alidayu;
use app\common\lib\IAuth;
use app\common\lib\Jpush;
use think\Controller;
use think\Exception;

use app\common\lib\exception\ApiException;

class Test extends Common
{

    public function index()
    {
        return 'sss';
    }

    public function update($id = 111)
    {
        echo $id;

        $data = input('put.');

        halt($data);
    }

    public function delete($id = 111)
    {
        echo $id;

    }

    public function save($id = 111)
    {

//        try {
//            model('xxxx');
//        } catch (\Exception $e) {
//            return show(0, $e->getMessage(), '', 401);
//        }

        $data = input('post.');
//        if ($data['mt'] != 1) {
////            \exception('错误', 403);
////            throw new Exception('错误...', 403);
//            throw new ApiException('错误测试', 403);
//
//        }


        return show('1', 'ok', (new Aes())->encrypt(json_encode(input('post.'))), 202);
    }


    public function send()
    {
        $id = input('post.id');
        $sms = Sms::getInstance()->sendSms($id);
        halt($sms);

    }

    ///  APP登录和web
    // web phpsessionid  , app -> token(唯一性) ，在登录状态下 所有的请求必须带token, token-》失效时间


    public function token()
    {
        echo IAuth::setAppLoginToken();
    }


    public function pushtest()
    {
        $client = new \JPush\Client('6dd3ceb7f3f70284846971d4', '0b10bbec153dadf257d047e7');
        $pusher = $client->push();
        $pusher->setPlatform('all');
        $pusher->addAllAudience();
        $pusher->setNotificationAlert('Hello, JPush');
        try {
            $pusher->send();
        } catch (\JPush\Exceptions\JPushException $e) {
            // try something else here
            print $e;
        }
    }

    public function push()
    {
        $obg = new Jpush();
        Jpush::push('miaosuwulimi', 2);
    }


}

